<?php
require_once 'BaseController.php';

/**
 * 店舗詳細コントローラクラス<br />
 *
 * @package apamanshop
 * @author　
 * @copyright　
 */
class Shop_ShopdtlController extends Shop_BaseController
{
	/**
	 * メインアクション
	 *
     * @access public
     * @return void
	 */
	public function indexAction()
	{
		
		if (Apm_Config_Search::RENEW_2012) {
			$this->_newTemplate = true;
			$this->_import_seo_search = true;
			// テンプレート変更
			$this->_detail_helper = $this->getApmHelper('detail/detail_new_helper.tpl');
		}
		
	    //　CMS用パラメータ設定
        $this->setCmsParams();
		// モデルインスタンス生成
        $this->_model = new Shop_Model_Detail();
        // 外部モデル呼び出し設定
		$loader = new Zend_Application_Module_Autoloader(array(
			'namespace' => 'Rstdtl',
			'basePath' => APPLICATION_PATH . '/modules/rstdtl',
		));
		$this->_model_rstdtl = new Rstdtl_Model_Bukendtl();

        // 利用ｻｲﾄ区分
        if (empty($this->_params['UseKbn']))
        {
        	$this->_params['UseKbn'] = '0';
        }

		/* 2011/07/22　AKBｷｬﾝﾍﾟｰﾝ：加盟店ﾒﾝﾊﾞｰｻｲﾄ追加対応 */
		//加盟店ページより遷移時は余分なパラメタを削除　ココから通常ヘッダサイトに戻る為
		if($this->_params['shoppage']){
	    	$this->_params['OemCd'] = '';
	    	$this->_params['PrefCd'] = '';
		}

		$OemCd = $this->getParamValue('OemCd');
		if ($OemCd == '') $OemCd = null;

		if (is_null($OemCd) == false)
		{
			// ヘッダー・フッターを表示しないようにする
			$this->setXPassThroutgh();
			if ($this->_newTemplate) {
				$this->_display_path = APPLICATION_PATH . '/modules/shop/views/scripts/shopdtl_no_header_new.tpl';
			} else {
				$this->_display_path = APPLICATION_PATH . '/modules/shop/views/scripts/shopdtl_no_header.tpl';
			}
            // プレースフォルダを除去
            $this->_remove_place_folder = true;
		}
		else if ($this->_newTemplate) {
			$this->_display_path = APPLICATION_PATH . '/modules/shop/views/scripts/shopdtl_new.tpl';
		}
		else {
			$this->_display_path = APPLICATION_PATH . '/modules/shop/views/scripts/shopdtl.tpl';
		}

        $shopCd = $this->getParamValue('ShopCd');

        // 店舗コードが存在しない場合
        if (is_null($shopCd))
        {
        	//$this->_main_helper = '店舗コードが存在しません';
			Apm_Util::redirect('/shop/shopdtl?ShopCd=0');
		    exit;
        }

        // アパマンショップコリアは、リダイレクト
        if ($shopCd == 'korea001')
        {
        	Apm_Util::redirect('http://www.apamanshop.co.kr/jp/');
        }

        $this->_params['ShopCd'] = $shopCd;
        // 店舗詳細情報取得
        $shopDtlList = $this->_model->getList($this->_params);

        // 店舗が存在しない場合
        if (count($shopDtlList) == 0)
        {
        	//$this->_main_helper = '該当する店舗は有りません';
	        $this->setBreadCrumb("&nbsp;"); // パンくずリスト対応(nullが表示されないように)
	        $this->_display_path = APPLICATION_PATH . '/modules/common/views/scripts/empty.tpl';
		    $this->display($this->_display_path);
        	exit;
        }


		//isBukenDtlが存在すれば、物件詳細からの遷移と判断
		if(!empty($this->_params['isBukenDtl']) &&
		   !empty($this->_params['ID']))
		{
			// インスタンス生成
    		$loader = new Zend_Application_Module_Autoloader(array(
				'namespace' => 'Rstdtl',
				'basePath' => APPLICATION_PATH . '/modules/rstdtl',
			));
			//物件詳細クラス
			$this->_model_rstdtl_bukendtl = new Rstdtl_Model_Bukendtl();

			// 物件情報を取得
			$this->_params['ID'] = $this->_params['t03HeyaCd']; //t03HeyaCdをIDに詰め替える
			$bukenData[0] = $this->_model_rstdtl_bukendtl->getBukenDtlData($this->_params);

			// 店別情報を取得するため、強制的にOemCdをセットする
			$isOemFlg = true;
			if(!array_key_exists('OemCd',$this->_params)){
				$isOemFlg = false;
				$this->_params['OemCd'] = '9999';
			}

			// 表示用にコンバート
			$this->_model_rstdtl_bukendtl->convertData($this->_config,&$bukenData,$this->_params);
			$this->_data['bukenDtl'] = &$bukenData[0];

			// OEMではなかった場合は、OemCdを念のため削除
			if(!$isOemFlg){
				unset($this->_params['OemCd']);
			}
		}

		// 店舗スタッフコメント取得
		//$staffCommentData = $this->_model->getStaffComment($shopCd);
		//$this->_data['staffComment'] = $this->_model->convertStaffComment($staffCommentData);

        // 表示用に変換
        $this->_data['shopDtl'] = $this->_model->convertData($shopDtlList[0], $this->_apalogurl, $this->_tenpoimageurl);
        $this->_data['shopDtl']['M05_HOUZINMEI'] = Apm_Util::replaceUnicode($this->_data['shopDtl']['M05_HOUZINMEI']);
        // PV増分処理
        $this->_model_rstdtl->S_RegPageViewLog($this->_data['shopDtl']['M05_TENPO_CD'], 1, 0, "NULL", 1);

        // QRコード生成
        $this->_data['qr'] = array(
		    'url'     => $this->_baseurl . $this->deleteDiagonal(Apm_Config_Shop::URL_MAP) . '?ShopCd=' . $this->_data['shopDtl']['M05_TENPO_CD'],
		    'width'   => '500',
		    'height'  => '500',
        	'img'     => array(
        		'alt'     => 'QRコード',
			    'width'   => '78',
			    'height'  => '78'
        	)
		);
		// QRヘルパー
        $this->_data['qr_helper'] = APPLICATION_PATH . '/modules/common/views/helpers/qr.tpl';
        // twitter情報取得
        $this->_data['twitter'] = $this->_model->getTwitterInfo($shopCd);
        // キャンペーン物件有無取得
        $this->_data['campaignBukken'] = $this->_model->getCampaignBukken($shopCd);
        $this->_data['campaignExile']  = $this->_model->getCampaignExile($shopCd);
        // タイトル等設定
        $this->setCmsParamsForTitle();
		if ($this->_newTemplate && isset($this->_data['shopDtl'][M05_TENPO_TODOUFUKEN_CD])) {
			// SEOランキングリンク
			// 初期化
			$rank_data = array();
			// テンプレート
			$ranking_block = $this->getApmHelper('search/views/helpers/seo_ranking_leftpanel.tpl');
			// ** こだわり取得 **
			$rank_data['RANK_KODAWARI'] = Apm_Seo::getSeoRankingKodawari(5, 8, $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN_CD']);
			// ** 建物種別取得 **
			$rank_data['RANK_TYPE']     = Apm_Seo::getSeoRankingType(array(), $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN_CD']);
			// ブロック生成
			$this->_data['ranking_block'] = $ranking_block->getBlock($rank_data);
			
			// サジェストリンクの取得
			$this->_data['suggestBlockData'] = Apm_Seo::getSuggestLinkBlockData($this->_data['shopDtl'][M05_TENPO_TODOUFUKEN_CD],15,5,5,15);
			// 2013/02/04 サジェストリンク追加対応 ss-sakakibaraw
			$this->_data['suggest_block'] = $this->_suggest_leftpanel_helper->getBlock($this->_data);
			
			//2013/02/14 新着リンク追加対応
			$this->_data['shinchakuBlockData'] = Apm_Seo::getTenpoShinchakuBlockData($this->_data['shopDtl'][M05_TENPO_CD],0);
			$this->_data['shinchaku_block'] = $this->_shinchaku_leftpanel_helper->getBlock($this->_data);
		}
		// パンくず設定
		$shopNo = $this->getParamValue('ShopNo');
		if (is_null($shopNo) == false)
		{
			$this->_breadcrumb->reset();
			$this->_breadcrumb->add(Apm_Config_Search::BREADCRUMB_TOP, $this->_baseurl);
			$url = $this->_baseurl . $this->deleteDiagonal(Apm_Config_Shop::URL_INDEX) . $this->createUrlParams();
			$this->_breadcrumb->add('店舗検索', $url, 'shopindex');
			$url = $this->_baseurl . $this->deleteDiagonal(Apm_Config_Shop::URL_DETAIL) . $this->createUrlParams();
			$this->_breadcrumb->add('店舗詳細', $url, 'shopdetail');
		} else {
			$params = array();
			$params = $this->_params;
			$params['PrefCd'][] = $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN_CD'];
			$params['CityCd'][] = $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN_CD'].$this->_data['shopDtl']['M05_TENPO_SHIKUCHOUSON_CD'];
			Apm_Bukkenbreadcrumb::generateBreadcrumbShop($params, $this->_breadcrumb);
			$url = Apm_Bukkenurl::generateUrlByParametersShopDetail($this->_data['shopDtl']);
			$this->_breadcrumb->add($this->_data['shopDtl']['M05_TENPO_NAME'], $url, 'shopdetail');
		}
        // メイン
        $this->_main_helper = $this->_detail_helper;
	}

	/**
	 * CMS用パラメータ設定
	 */
	private function setCmsParams()
	{
		//$this->_data['googlemap']['key'] = $this->_googleMapKey;
		//$this->addMetaJs('http://maps.google.com/maps?file=api&v=2&key=' . $this->_googleMapKey, array('charset' => 'utf-8'));
		
		if ($this->_newTemplate) {
			// css
			//$this->addMetaCss('/common_new/css/sub.css', array('media'=>'all'));
			$this->addMetaCss('/common_new/css/sub02.css', array('media'=>'all'));
			$this->addMetaCss('/common_new/css/shop.css', array('media'=>'all'));
			$this->addMetaCss('/css/shop/shop.css');
			//$this->addMetaCss('/css/search/search.css');
			// javascript
			$this->addMetaJs('/common_new/js/import_shp.js');
	        $this->addMetaJs('/app/js/shop/mapple.js');
	        $this->addMetaJs('/app/js/mapple/lib/Mapple.js');
			$this->addMetaJs('/app/js/mapple/lib/slider.js');
			$this->addMetaJs('/app/js/mapple/lib/scrollmap.js');
		} else {
			// javascript
			$this->addMetaJs('/js/common/photo.js');
			$this->addMetaJs('/app/js/shop/ew.js');
			$this->addMetaJs('/app/js/shop/constant.js');
			//$this->addMetaJs('/app/js/shop/gmap.js');
	        $this->addMetaJs('/app/js/shop/mapple.js');
	        $this->addMetaJs('/app/js/mapple/lib/Mapple.js');
			$this->addMetaJs('/app/js/mapple/lib/slider.js');
			$this->addMetaJs('/app/js/mapple/lib/scrollmap.js');
			
			$this->addMetaJs('/app/js/shop/mobile.js');
			$this->addMetaJs('/app/js/shop/shop.js');
			//$this->addMetaJs($this->_aplbaseurl . 'js/rstdtl/bukendtl.js');
			$this->addMetaJs('/app/js/Rstobi.js');
			$this->addMetaJs('/app/js/search/Chizusearch.js');
			// css
			$this->addMetaCss('/css/shop/shop.css');
			$this->addMetaCss('/css/search/search.css');
		}
	}

	/**
	 * CMS用パラメータ（タイトル等）設定
	 */
	private function setCmsParamsForTitle()
	{
		$property = array();
		$shopWord = $this->_data['shopDtl']['M05_TENPO_NAME'] . '（' . $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN'] . $this->_data['shopDtl']['M05_TENPO_SHIKUCHOUSON'] . '）';
		
		if ($this->_newTemplate) {
			$shopWord = 'アパマンショップ'.$this->_data['shopDtl']['M05_TENPO_NAME'] . $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN'] . $this->_data['shopDtl']['M05_TENPO_SHIKUCHOUSON'];
			$property['title'] = $shopWord . Apm_Config_Seo::TITLE_ADDTAIL;
			$property['description'] = $shopWord . 'の店舗情報。' . Apm_Config_Seo::DESCRIPTION_ADDTAIL;
			$property['keywords'] = Apm_Config_Seo::KEYWORD_ADDTAIL;
			$property['h1_title'] = '<span id="shopName">'.'アパマンショップ'.$this->_data['shopDtl']['M05_TENPO_NAME'].'</span>&nbsp;<strong class="text_s">'
			                       .$this->_data['shopDtl']['M05_TENPO_TODOUFUKEN'] . $this->_data['shopDtl']['M05_TENPO_SHIKUCHOUSON'].'。'.Apm_Config_Seo::H1_ADDTAIL.'</strong>';
			$shopWord = $this->_data['shopDtl']['M05_TENPO_NAME'] . '/' . $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN'] . $this->_data['shopDtl']['M05_TENPO_SHIKUCHOUSON'];
			$property['unique_text'] = $shopWord.'の賃貸住宅・賃貸マンション・賃貸アパートの検索はアパマンショップ！'.$shopWord.'のペット相談可物件や、敷金礼金ダブル0の賃貸物件など、アパマンショップならではの情報が満載です。<br />'
			                         . '日本最大級のネットワークで'.$shopWord.'の賃貸物件、賃貸マンション、賃貸アパートを探せます。'.Apm_Config_Seo::UNIQUE_TEXT_ADDTAIL;
		} else {
			$property['title'] = '賃貸情報アパマンショップ[アパマンショップ' . $shopWord . ']';
			$property['description'] = 'アパマンショップ' . $shopWord . 'の店舗情報。賃貸住宅、賃貸マンション、賃貸アパート、賃貸不動産情報を多数取り扱っております。';
			$property['keywords'] = $this->_data['shopDtl']['M05_TENPO_NAME'] . ',' . $this->_data['shopDtl']['M05_TENPO_TODOUFUKEN'] . '' . $this->_data['shopDtl']['M05_TENPO_SHIKUCHOUSON'] . ',賃貸,アパマンショップ,賃貸情報,賃貸住宅,賃貸マンション,賃貸アパート,賃貸住宅情報,賃貸不動産,賃貸検索,不動産賃貸,不動産,アパマン,あぱまん,apaman';
			$property['h1_title'] = '<span id="shopName">アパマンショップ' . $this->_data['shopDtl']['M05_TENPO_NAME'].'</span>';
			$property['unique_text'] = '';
		}
		
		// タイトル設定
		$this->setTitle($property['title']);
		// Description設定
		$this->setDescription($property['description']);
		// Keyword設定
		$this->setKeywords($property['keywords']);
		// H1
		$this->_data['h1_title'] = $property['h1_title'];
		// ユニークテキスト
		$this->_data['unique_text'] = $property['unique_text'];
		
		$this->_data['property'] = $property;
	}
}
?>
